<template>
  <div>
    <edit-course :ruleForm="ruleForm" @editOrAdd="editCourse"></edit-course>
  </div>
</template>
<script>
import EditCourse from '@/views/course/editOrAddCmp'
import {editClass, createUpdateClass} from '@/api/operation'
import {ERR_OK} from '@/api/config'
export default {
  data() {
    return{
      ruleForm: {}
    }
  },
  methods: {
    editCourse(params) {
      this._editCourse(params)
    },
    _editCourse(params) {
      createUpdateClass(params)
        .then((res) => {
          console.log(res)
        })
        .catch((err) => {
          console.log(err)
        })
    },
    _getCourseInfo(id) {
      editClass(id)
        .then((res) => {
          if (res.code == ERR_OK) {
            // Object.assign(this.ruleForm, res.list, {chapter_name: JSON.stringify(res.list[chapter_name])})
            this.ruleForm = res.list
            // console.log(this.ruleForm)
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  },
  created() {
    let params = Object.assign({}, {class_relationship_id: this.$route.params.id})
    this._getCourseInfo(params)
  },
  components: {
    EditCourse
  }
}
</script>
<style lang="scss" scoped>

</style>